import {globalConfig} from "../consts/GlobalConfig";
import {bannerAds} from "../../framework/wx/AdsProvider";

/**
 * 通用的用于切换banner.
 */
class CrossAdsHelper {
    private crossNode: cc.Node = null;
    private currentCrossCounter: number = 0;

    public setCrossContainer(crossNode: cc.Node) {
        this.crossNode = crossNode;
    }

    public showBannerOrCross() {
        switch (globalConfig.bannerCfg.mode) {
            case 0: {
                this.crossNode.active = true;
                bannerAds.hideAds();
                cc.log("展示cross");
                break;
            }
            case 1: {
                cc.log("展示banner");
                this.crossNode.active = false;
                bannerAds.showAds(1);
                break;
            }
            case 2: {
                cc.log("banner/cross 都不展示.");
                this.crossNode.active = false;
                bannerAds.hideAds();
                break;
            }
            case 3: {
                this.currentCrossCounter = (this.currentCrossCounter + 1) % (globalConfig.bannerCfg.step + 1);
                if (this.currentCrossCounter == 0) {
                    globalConfig.bannerCfg.showing = (globalConfig.bannerCfg.showing + 1) % 2;
                }
                if (globalConfig.bannerCfg.showing == 0) {
                    cc.log("展示banner");
                    this.crossNode.active = false;
                    bannerAds.showAds(1);
                } else {
                    cc.log("展示cross");
                    this.crossNode.active = true;
                    bannerAds.hideAds();
                }
                break;
            }
        }
    }
}

export const crossAdsHelper: CrossAdsHelper = new CrossAdsHelper();